package setting

import (
	"../common"
	"../web"
	"strings"
)

type SetSysLockObj struct {
	common.BaseHandler
}

func (self *SetSysLockObj) Prepare() {}

func (self *SetSysLockObj) ParameterCheck() bool {
	c_type := self.Ctx.Params["locktype"]
	c_actn := self.Ctx.Params["action"]
	c_lkno := strings.TrimSpace(self.Ctx.Params["lockno"])
	if c_lkno == "" {
		self.TmplData["error"] = common.GetText(self.Lang, "Please input the lock No.")
		return false
	}

	self.Sqlparas = append(self.Sqlparas, c_type)
	self.Sqlparas = append(self.Sqlparas, c_actn)
	self.Sqlparas = append(self.Sqlparas, c_lkno)
	self.Sqlparas = append(self.Sqlparas, self.Usr.Username)
	self.Flashparas = []interface{}{c_actn, c_lkno}

	return true
}

func (self *SetSysLockObj) SqlExecute() bool {
	spRtnData := *common.FetchOneRowPtr(
		`sp_SystemLock ?, ?, ?, ?`,
		self.Usr.Conn, new(common.SPReturn), self.Sqlparas...)
	if spRtnData.(common.SPReturn).Flag > 0 {
		self.TmplData["error"] = common.GetTextSP(self.Lang, spRtnData)
		return false
	}
	return true
}

func SysLockSetHandler(ctx *web.Context) {
	self := new(SetSysLockObj)
	self.Ctx = ctx
	self.Url = "/syslock"
	self.Html = "syslock.html"
	self.Rightlist = []string{"syslock"}
	self.Flashstr = "System %v: [ %v ] finished."
	self.Do(self)
}
